package 力扣;

/**
 * @author ZhuYi
 * @create 2024/7/23 11:03
 */
public class 买卖股票的最佳时机_121 {
    public static void main(String[] args) {
        int[] prices = {2,4,1};
        System.out.println(maxProfit(prices));
    }

    public static int maxProfit(int[] prices) {
        int min = Integer.MAX_VALUE;
        int max = 0;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < min) {
                min = prices[i];
            } else if (prices[i] - min > max) {
                max = prices[i]-min;
            }
        }
        return max;

    }
}
